
class Airplane extends egret.DisplayObjectContainer {
	
	private bmp:egret.Bitmap;
	public textureName:string;

	private fireDelay:number;
	private fireTimer:egret.Timer;
	public blood:number = 10;
	
	
	public constructor(texture:egret.Texture, fireDelay: number) {
		super();

		this.fireDelay = fireDelay;
		this.bmp = new egret.Bitmap(texture);
		this.addChild(this.bmp);

		this.fireTimer = new egret.Timer(fireDelay);
		this.fireTimer.addEventListener(egret.TimerEvent.TIMER, this.createBullet, this);
	}

	private createBullet(et: egret.TimerEvent) {
		this.dispatchEventWith("createBullet");
	}

	public fire() {
		this.fireTimer.start();
	}

	public stopFire() {
		this.fireTimer.stop();
	}

	private static cacheDict:Object = {};


	public static produce(textureName:string, fireDelay:number):Airplane {
		
		if (Airplane.cacheDict[textureName] == null) {
			Airplane.cacheDict[textureName] = [];
		} 

		var arr:Airplane[] = Airplane.cacheDict[textureName];
		var fighter : Airplane;
		if (arr.length > 0) {
			fighter = arr.pop();
		} else {
			fighter = new Airplane(RES.getRes(textureName), fireDelay);
		}
		fighter.blood = 10;
		fighter.textureName = textureName;
		return fighter;
	}


	public static reclaim(fighter:Airplane) {
		if (Airplane.cacheDict[fighter.textureName] == null) {
			Airplane.cacheDict[fighter.textureName] = [];
		}
		var arr:Airplane[] = Airplane.cacheDict[fighter.textureName];
		if (arr.indexOf(fighter) == -1) {
			arr.push(fighter);
		}
	}




}